from fastapi import APIRouter
import os
from datetime import datetime
from schemas import ModelInfo
from core.config import settings  # 新添加这一行
from typing import List


router = APIRouter(prefix="/models", tags=["models"])

@router.get("/", response_model=List[ModelInfo])
async def get_models():
    models = []
    for file in os.listdir(settings.MODELS_DIR):
        if file.endswith(".pth"):
            created_at = datetime.fromtimestamp(os.path.getctime(os.path.join(settings.MODELS_DIR, file))).strftime("%Y-%m-%d")
            models.append(ModelInfo(id=file, name=file, createdAt=created_at))
    return models



